#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
const int maxn = 5005,INF = INT_MAX;

int n,a[maxn],dp[maxn];

int solve(){
	fill(dp,dp+n,INF);
	for(int i=0;i<n;i++){
		dp[lower_bound(dp,dp+n,a[i])-dp] = a[i];
	}
	return lower_bound(dp,dp+n,INF)-dp;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cout<<solve()<<endl;
	return 0;
}